package DAOJPA;

import java.util.List;



import recompenses.RecompenserFilm;
import recompenses.RecompenserPersonne;
import DAO.DAO;
import DAO.DAORecompenserPersonne;

public class DAORecompenserPersonneJPA extends DAO implements DAORecompenserPersonne{

    static private DAORecompenserPersonneJPA instance = null;
	
	private DAORecompenserPersonneJPA() {
	}
		static public DAORecompenserPersonne getInstance() {
		 	if (instance == null)
				instance = new DAORecompenserPersonneJPA();
			 	
		 	return instance;
	}
	
	@Override
	public RecompenserPersonne getRecompenserPersonne(int code, int code2) {
		// TODO Auto-generated method stub
		return DAO.getManager().createQuery("SELECT a FROM RecompenserPersonne a WHERE a.id.code_per =:code AND a.id.code_rec =:code2 ", RecompenserPersonne.class).setParameter("code", code).setParameter("code2", code2).getSingleResult();
		
	}

	
	@Override
	public List<RecompenserPersonne> getRecompenseInvalide() {
		// TODO Auto-generated method stub
		return DAO.getManager().createQuery("SELECT a FROM RecompenserPersonne a WHERE a.valide =:code ", RecompenserPersonne.class).setParameter("code", 1).getResultList();
		
	}
	
	@Override
	public List<RecompenserPersonne> loadAll() {
		// TODO Auto-generated method stub
		return DAO.getManager().createQuery("SELECT a FROM RecompenserPersonne a", RecompenserPersonne.class).getResultList();

	}

	@Override
	public int getNombreRecompenserPersonne() {
		// TODO Auto-generated method stub
		return this.loadAll().size();
	}

	@Override
	public void save(RecompenserPersonne a) {
		DAO.getManager().persist(a);
		DAO.commit();
	}

	@Override
	public void delete(RecompenserPersonne a) {
		getManager().remove(a);
		DAO.commit();
	}

}
